package com.gome.axwl.aoc.web.controller.quartzJob;

import com.gome.axwl.aoc.common.util.BeanJsonUtil;
import com.gome.axwl.aoc.common.util.DateUtil;
import com.gome.axwl.aoc.entity.mq.ImPushMsgMQEntityV31;
import com.gome.axwl.aoc.entity.po.MpResult;
import com.gome.axwl.aoc.web.controller.mq.producer.ImProducer;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Description: 司机积分计算定时任务
 * @Auther: yinyuxin@gome.com.cn
 * @Date: 2018/5/2 18:30
 */
@Component
@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class DriverIntegrationJob implements Job {

    private static final Logger LOGGER=LoggerFactory.getLogger(RuleInitJob.class);
    @Autowired
    private ImProducer imProducer;

    @Value("${gomeAxwlAocDriverIntegrationTag}")
    private String gomeAxwlAocDriverIntegrationTag;


    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        LOGGER.info("quartz定时计算司机积分任务开始启动,时间{}",DateUtil.date2String(new Date(),DateUtil.FORMAT_DEFAULT));
        String driverIntegrationDate=DateUtil.date2String(DateUtil.timeCalculation(new Date(),-1,1),DateUtil.FORMAT_DATE_WITHOUT_DAY);
        try {
            //司机积分的任务调度只用于定时调用积分生成的方法类，不包含任何业务逻辑

            ImPushMsgMQEntityV31 mqEntityV31=new ImPushMsgMQEntityV31();
            MpResult mpResult=new MpResult();
            mpResult.setMsgContent(driverIntegrationDate);
            mqEntityV31.setMpResult(mpResult);
            imProducer.send(gomeAxwlAocDriverIntegrationTag, mqEntityV31);
             LOGGER.info("quartz定时计算司机积分任务启动成功,发送的mq,tag{},内容{}",gomeAxwlAocDriverIntegrationTag,BeanJsonUtil.obj2String(mqEntityV31));

        } catch (Exception e) {
            LOGGER.error("quartz定时计算司机积分任务启动失败,时间{},详情{}",driverIntegrationDate,ExceptionUtils.getFullStackTrace(e));
            throw new RuntimeException();
        }
    }



}
